/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cconverter;

import java.io.*;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author SapunBoj
 */
public class Props {

    public static FileInputStream fis;
    public static FileOutputStream fos;
    public static Properties prop = new Properties();

    public Props(){
        if (!checkFile()) {
            try {
                makeFile();
            } catch (IOException ex) {
                Logger.getLogger(Props.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        try {
            loadProperties();
        } catch (IOException ex) {
            Logger.getLogger(Props.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void loadProperties() throws IOException {
        fis = new FileInputStream(Sets.optionsfile);
        prop.load(fis);
    }

    public void storeProperties() throws IOException {
        fos = new FileOutputStream(Sets.optionsfile);
        prop.store(fos, "Options");
        fos.close();
    }

    public void setProp(String key, String value) {
        prop.setProperty(key, value);
    }

    public String getProp(String key, String def) {
        return prop.getProperty(key, def);
    }

    public boolean checkFile() {
        if (new File(Sets.optionsfile).exists()) {
            return true;
        } else {
            return false;
        }
    }

    public void makeFile() throws IOException {
        if (!this.checkFile()) {
            new File(Sets.optionsfile).createNewFile();
        }
    }
}
